package com.renke.enml;

public class MathExpression extends Expression {

	private Expression thisExp;
	private Expression nextExp;
	private String operator;
	private boolean negate;

	MathExpression(Expression thisExp, Expression nextExp, String operator) {
		super(format(thisExp, nextExp, operator));
		this.thisExp = thisExp;
		this.nextExp = nextExp;
		this.operator = operator;
	}

	private static String format(Expression thisExp, Expression nextExp, String operator) {
		return (thisExp instanceof MathExpression ? "(" : "") + thisExp + (thisExp instanceof MathExpression ? ")" : "") + operator
				+ (nextExp instanceof MathExpression ? "(" : "") + nextExp + (nextExp instanceof MathExpression ? ")" : "");
	}

	public Expression getNextExp() {
		return nextExp;
	}

	public void setNextExp(Expression nextExp) {
		this.nextExp = nextExp;
	}

	public Expression getThisExp() {
		return thisExp;
	}

	public void setThisExp(Expression thisExp) {
		this.thisExp = thisExp;
	}

	public String getOperator() {
		return operator;
	}

	public void setOperator(String operator) {
		this.operator = operator;
	}

	public MathExpression negate() {
		negate = !negate;
		return this;
	}

}
